﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ServiceStack.Redis;

namespace StyleTest.Controllers
{
    public static class RedisHelper
    {
        #region static field
        private static IRedisClient _redisClient= null;
        private static IRedisClient RedisClient
        {
            get
            {
                if (_redisClient == null)
                {
                    _redisClient = new RedisClient("127.0.0.1", 6379);
                    _redisClient.Password = "caonimadaohao123";
                }
                return _redisClient;
            }
        }
        #endregion
        #region
        /// <summary>
        /// 获取信息
        /// </summary>
        /// <typeparam name="T">对象类型</typeparam>
        /// <returns>对象</returns>
        public static T Get<T>(string token) 
        {
            return RedisClient.Get<T>(token);
        }
        /// <summary>
        /// 设置信息
        /// </summary>
        /// <typeparam name="T">对象类型</typeparam>
        /// <param name="token">key</param>
        /// <param name="obj">对象</param>
        public static void Set<T>(string token, T obj,DateTime expressTime) 
        {
            RedisClient.Set<T>(token, obj,expressTime);
        }
        #endregion
    }
}